public class 删除排序链表中的重复元素II {
    class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
    public ListNode deleteDuplicates(ListNode head) {
        // 虚拟头节点指向
        ListNode t = new ListNode();
        t.next = head;
        ListNode cur = t;
        while (cur.next != null && cur.next.next != null) {
            if (cur.next.val != cur.next.next.val) {
                cur = cur.next;
            } else {
                int x = cur.next.val; // 相同的元素提取
                ListNode next1 = cur.next;
                while (next1 != null && next1.val == x) {
                    next1 = next1.next;
                }
                cur.next = next1;
            }
        }
        return t.next;
    }
}
